﻿using LX.Core.Validation;
using S4Store.Domain;
using S4Store.Persistent;
using System.Linq;

namespace S4Store.Service.Valid.CarValid
{
    public class PinpaiModify : ValidExpression<PinPai>
    {
        public S4StoreDataContext PersistentContext { get; set; }

        public override void ValidEntity(ValidationResult result, PinPai entity)
        {
            NoEmpty(result, "名称", entity.Name);
            if (PersistentContext.Set<PinPai>().AsQueryable().FirstOrDefault(t => t.Name == entity.Name && t.Id != entity.Id) != null)
            {
                PushError(result, "已存在相同名称的品牌");
            }
        }
    }
}
